package com.gxa.xc.rbac.controller;

import com.gxa.xc.rbac.dto.ResultDTO;
import com.gxa.xc.rbac.pojo.Admin;
import com.gxa.xc.rbac.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * 登陆相关的控制器
 * @author:IT-CNLM
 * @date:Created at 2020/10/21
 */
@Controller
@RequestMapping("/login")
public class LoginController {


    @Autowired
    private LoginService loginService;

    /**
     * 登陆页
     * @return
     */
    @GetMapping("/page")
    public String loginPage(){
        return "login";
    }


    /**
     * 登陆的方法
     * @param admin
     * @return
     */
    @PostMapping("/do")
    @ResponseBody
    public ResultDTO loginDo(Admin admin, HttpSession session){
        return loginService.login(admin, session);
    }

@PostMapping("/out")
@ResponseBody
    public ResultDTO logout(HttpSession session){
        session.removeAttribute("adminName");
        return new  ResultDTO(200,"退出成功");
    }


}
